import cv2
from utils.common import load_image, show_image, make_dirs  # 导入公共函数
from utils.config import exp2_gray_path, exp2_mean_blur_path, exp2_gaussian_blur_path, exp2_median_blur_path, exp2_output_dir  # 导入输出路径

# 确保输出目录存在
make_dirs(exp2_output_dir)

# 加载灰度图像
gray_image = cv2.imread(exp2_gray_path, cv2.IMREAD_GRAYSCALE)

# 均值滤波
mean_blurred = cv2.blur(gray_image, (5, 5))
show_image("Mean Blurred", mean_blurred)

# 高斯滤波
gaussian_blurred = cv2.GaussianBlur(gray_image, (15, 15), 0)
show_image("Gaussian Blurred", gaussian_blurred)

# 中值滤波
median_blurred = cv2.medianBlur(gray_image, 5)
show_image("Median Blurred", median_blurred)

# 保存结果
cv2.imwrite(exp2_mean_blur_path, mean_blurred)
cv2.imwrite(exp2_gaussian_blur_path, gaussian_blurred)
cv2.imwrite(exp2_median_blur_path, median_blurred)
print(f"均值滤波结果已保存到：{exp2_mean_blur_path}")
print(f"高斯滤波结果已保存到：{exp2_gaussian_blur_path}")
print(f"中值滤波结果已保存到：{exp2_median_blur_path}")